#ifndef BRIDGEUTILS_H_
#define BRIDGEUTILS_H_

#include <ext/hash_map>
namespace stdext
{
	using namespace __gnu_cxx;
}

#include <boost/shared_ptr.hpp>

#include <jni.h>

#include "graph_support/utils/HashSupport.h"

namespace native_orbitor
{

template < typename T >
void deleteMe( int ptr2T_asInt )
{
	T * t = reinterpret_cast< T * >( ptr2T_asInt );
	delete t;
}

template < typename NativeObjT, typename ExchPtrT >
ExchPtrT createObjectAndDeleteFn( JNIEnv * env, jintArray output )
{
	std::auto_ptr< ExchPtrT > objectPtrGuart(
			new ExchPtrT( new NativeObjT() ) );
	int objectExchPtrInt = reinterpret_cast< int >( objectPtrGuart.get() );

	void ( * deleteFunc ) ( int ) = & ( deleteMe< ExchPtrT > );
	int deleteFuncInt = reinterpret_cast< int >( deleteFunc );

	int result[] = { objectExchPtrInt, deleteFuncInt };
	env->SetIntArrayRegion( output, 0, 2, result );
	/**
	 * output owns the pointer
	 * while return resultEP may be ignored
	 */
	ExchPtrT * resultEP = objectPtrGuart.release();

	return * resultEP;
}

const std::string jstr2stdstr( JNIEnv * env, jstring s );

typedef stdext::hash_map<
		std::string, double,
		GRAPH_SUPPORT_NS::utils::Hash4StdString
		> NativeObjectFieldsMap;
NativeObjectFieldsMap parseGenSettingsMap( JNIEnv * env, jobject grGenSettings );

void jthrow( JNIEnv * env, const std::string & exceptionClassName, const std::string & message );

}

#endif /* BRIDGEUTILS_H_ */
